package com.wxl.asmgradleplugin.myplugin


import com.android.build.api.instrumentation.AsmClassVisitorFactory
import com.android.build.api.instrumentation.ClassContext
import com.android.build.api.instrumentation.ClassData
import com.android.build.api.instrumentation.InstrumentationParameters
import org.gradle.api.tasks.Input
import org.objectweb.asm.ClassVisitor

internal interface MyParameters : InstrumentationParameters {
    @get:Input
    var param: String
}

abstract class LogClassVisitorFactory : AsmClassVisitorFactory<MyParameters> {

    override fun isInstrumentable(classData: ClassData): Boolean {
        val className = classData.className
        val b = className.startsWith(Consts.PK)
        if (b) println("======222 className=$className")
        return b
    }

    override fun createClassVisitor(
        classContext: ClassContext, nextClassVisitor: ClassVisitor
    ): ClassVisitor {
        println("======222 param=${parameters.get().param}")
        return LogClassVisitor(instrumentationContext.apiVersion.get(), nextClassVisitor)
    }

}